package com.sugon.controller.device;

import com.sugon.entity.DevReportUrgeEntity;
import com.sugon.service.DevReportUrgeService;
import com.sugon.utils.PageUtils;
import com.sugon.utils.Query;
import com.sugon.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 报修催办记录Controller
 *
 * @author sugon
 * @date 2019-07-30 11:43:40
 */
@Controller
@RequestMapping("devreporturge")
public class DevReportUrgeController {
    @Autowired
    private DevReportUrgeService devReportUrgeService;

    /**
     * 查看列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("devreporturge:list")
    @ResponseBody
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<DevReportUrgeEntity> devReportUrgeList = devReportUrgeService.queryList(query);
        int total = devReportUrgeService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(devReportUrgeList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    /**
     * 根据报修编号,查询是否存在数据
     */
    @RequestMapping("/get/{REPAIRNO}")
//    @RequiresPermissions("devreporturge:info")
    @ResponseBody
    public R info(@PathVariable("REPAIRNO") String REPAIRNO) {
        Boolean isHas=false;
        Map query=new HashMap();
        query.put("repairNo",REPAIRNO);
        query.put("dealStatus",1);
        List<DevReportUrgeEntity> devReportUrgeList = devReportUrgeService.queryList(query);
        //已经催办
        if (devReportUrgeList.size()>0){
            isHas=true;
        }
        return R.ok().put("isHas", isHas);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
//    @RequiresPermissions("devreporturge:save")
    @ResponseBody
    public R save(@RequestBody DevReportUrgeEntity devReportUrge) {
        devReportUrgeService.save(devReportUrge.getRepairNo(),"REPAIR");

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
//    @RequiresPermissions("devreporturge:update")
    @ResponseBody
    public R update(@RequestBody DevReportUrgeEntity devReportUrge) {
        devReportUrgeService.update(devReportUrge);

        return R.ok();
    }
    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("devreporturge:delete")
    @ResponseBody
    public R delete(@RequestBody String[] ids) {
        devReportUrgeService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 查看所有列表
     */
    @RequestMapping("/queryAll")
    @ResponseBody
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<DevReportUrgeEntity> list = devReportUrgeService.queryList(params);

        return R.ok().put("list", list);
    }
    /**
     *  更新
     */

}
